<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Keu_closing extends MY_Controller {
	
	function __construct()
	{
		parent::__construct(); 
		
		$this->load->model('keu_closing_model', 'Closing');
		$this->load->model('combo_model', 'Combo');
		$this->secure_session();
	}
	
	function index(){
		$data['title'] = "GL Closing";
		$data['data']['month'] = date('m');
		$data['data']['year'] = date('Y');
		$data['month']		= json_encode($this->Combo->SWMonth());
		
		$arr_year = array(array("value"=> (date('Y')-1), "display"=>(date('Y')-1)),
							array("value"=> (date('Y')), "display"=>(date('Y'))),
							array("value"=> (date('Y')+1), "display"=>(date('Y')+1)));
		$data['year']		= json_encode($arr_year);
		
		viewByTemplate('keu_closing/index', $data, 'grid');
	}
	function getdata()
	{	
		echo $this->Closing->GetJSON();
	}
	
	function  check_closing(){
		$adt_transaksi = get('adt_transaksi');
		$as_kantor = get('as_kantor');
		$st_closing  = 0; 
		if ($adt_transaksi!='' && $as_kantor!=""){
			$st_closing = $this->get_data("SELECT COUNT(1) FROM KEU_CLOSING WHERE KD_KANTOR='".$as_kantor."' AND TO_CHAR(month_year,'YYYY-MM') = '".date_format3($adt_transaksi, 'YYYY-MM')."'");
		}
		echo $st_closing;
	}
	
	function closing_byoffice($month_year, $office_code, $status){
		$data['STATUS_CLOSED']	= $status;
		$data['MODIFY_DATE']	= NOW;
		$data['MODIFY_USER']	= USERID;
		$this->Closing->Update($data, array('MONTH_YEAR' => $month_year, 'KD_KANTOR'=>$office_code));	
	}
	
	function closing($month_year){
		$this->Closing->Closing($month_year."-01");	
	}
	
	function generate_closing($month_year){
		$this->Closing->Gen($month_year."-01");	
	}
	
	
	

	
}
?>